﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Scoreboard.Data;

namespace Scoreboard.Model
{
	public partial class User
	{	
		public string Name
		{
			get
			{
				if (!string.IsNullOrEmpty(FriendlyName))
				{
					return FriendlyName;
				}
				return Login;
			}
		}

		public bool IsCurrent
		{
			get
			{
				return Login.ToUpper() == WebContext.Current.User.Name.ToUpper();
			}
		}

		public bool IsAvailable
		{
			get
			{
				return !string.IsNullOrWhiteSpace(EmployeeId);
			}
		}

		public void NotifyRatingChanged()
		{
			RaiseDataMemberChanged("RatingValue");
			RaisePropertyChanged("RatingValue");
		}

		public override bool Equals(object obj)
		{
			var anotherUser = obj as User;
			if (anotherUser == null)
			{
				return false;
			}

			return this == anotherUser;
		}

		public override int GetHashCode()
		{
			return Login.GetHashCode();
		}

		public static bool operator ==(User user1, User user2)
		{
			if (System.Object.ReferenceEquals(user1, user2))
			{
				return true;
			}
			
			if (((object)user1 == null) || ((object)user2 == null))
			{
				return false;
			}
			
			return user1.Login.ToUpperInvariant() == user2.Login.ToUpperInvariant();
		}

		public static bool operator !=(User user1, User user2)
		{
			return !(user1 == user2);
		}
	}
}
